package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysAddress;
import com.ruoyi.project.system.domain.SysMobileUser;
import com.ruoyi.project.system.service.ISysAddressService;
import com.ruoyi.project.system.service.ISysMobileUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mobileUser/user/")
public class UserMobileController extends BaseController {

    @Autowired
    private ISysMobileUserService sysMobileUserService;

    @Autowired
    private ISysAddressService sysAddressService;

    // 用户信息修改 暂时为:头像用户名
    @RepeatSubmit
    @SignatureValidation
    @PostMapping("updateMobileUser")
    public AjaxResult queryMyService(@RequestBody SysMobileUser sysMobileUser) {
        return AjaxResult.success(sysMobileUserService.updateSysMobileUser(sysMobileUser));
    }

    @SignatureValidation
    @GetMapping("/list")
    public TableDataInfo list(SysMobileUser sysMobileUser) {
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        sysMobileUser.setMobileUserId(mobileUserId);
        List<SysAddress> sysAddresses = sysAddressService.selectSysAddressAllList(mobileUserId);
        startPage();
        List<SysMobileUser> list = sysMobileUserService.selectSysMobileUserList(sysMobileUser);
        for (int i = 0; i < list.size(); i++) {
            SysMobileUser user = list.get(i);
            user.setSysAddresses(sysAddresses);
        }
        return getDataTable(list);
    }
}
